package com.itkjb.leisurely.resource.sys.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.itkjb.leisurely.core.base.BaseConstants;
import com.itkjb.leisurely.core.base.BaseDto;
import com.itkjb.leisurely.core.base.BaseResult;
import com.itkjb.leisurely.core.base.controller.BaseController;
import com.itkjb.leisurely.resource.sys.model.SysStationRoleModel;
import com.itkjb.leisurely.resource.sys.service.ISysStationRoleService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import java.io.Serializable;
import java.util.List;
/**
 * <p>
 * 岗位绑定角色 接口层
 * </p>
 *
 * @author itkjb.com
 * @since 2020-08-11
 */
@RestController
@RequestMapping("/sys/sys-station-role")
@Api(value="岗位绑定角色",tags={"岗位绑定角色相关接口"})
public class SysStationRoleController extends BaseController<SysStationRoleModel,ISysStationRoleService> {

    /**
     * 获取岗位绑定角色列表
     * @param param 查询通用参数
     * @param model 特定条件参数
     * @param request
     * @param response
     * @return
     */
    @GetMapping
    @ApiOperation(value="获取岗位绑定角色列表",notes="支持分页参数")
    @PreAuthorize("hasAnyAuthority('SysStationRole','SysStation:SysStationRole','SysStation:query','SysStation:SysStationRole:query') || hasRole('"+ BaseConstants.ADMINISTRATOR_ROLE_CODE +"') ")
    public BaseResult<IPage<SysStationRoleModel>> page(BaseDto param, SysStationRoleModel model, HttpServletRequest request, HttpServletResponse response){
        BaseResult<IPage<SysStationRoleModel>> res = new BaseResult<>();
        res = super.page(param, model);
        return res;
    }

    /**
     * 获取岗位绑定角色列表
     * @param param 查询通用参数，分页参数不可用
     * @param model 特定条件参数
     * @param request
     * @param response
     * @return
     */
    @GetMapping("/list")
    @ApiOperation(value="获取岗位绑定角色列表",notes="不支持分页")
    @PreAuthorize("hasAnyAuthority('SysStationRole','SysStation:SysStationRole','SysStation:query','SysStation:SysStationRole:query') || hasRole('"+ BaseConstants.ADMINISTRATOR_ROLE_CODE +"') ")
    public BaseResult<List<SysStationRoleModel>> list(BaseDto param,SysStationRoleModel model, HttpServletRequest request, HttpServletResponse response){
        BaseResult<List<SysStationRoleModel>> res = new BaseResult<>();
        // 代码生成器生成的下面执行结果默认关闭，防止获取非法数据和数据量过大，若需要手动打开，并做好防护措施
        // return super.list(param, model);
        res.toSuccess().setMsg("注意：无结果返回，默认关闭list查询");
        return res;
    }

    /**
     * 新增岗位绑定角色
     * @param param
     * @param request
     * @param response
     * @return
     */
    @PostMapping
    @ApiOperation(value="新增岗位绑定角色",notes="")
    @PreAuthorize("hasAnyAuthority('SysStation:add','SysStation:SysStationRole:add') || hasRole('"+ BaseConstants.ADMINISTRATOR_ROLE_CODE +"') ")
    public BaseResult<SysStationRoleModel> add(@Valid @RequestBody SysStationRoleModel param, HttpServletRequest request, HttpServletResponse response){
        BaseResult<SysStationRoleModel> res = new BaseResult<>();
        res = super.add(param);
        return res;
    }

    /**
     * 获取岗位绑定角色详情
     * @param id
     * @param response
     * @return
     */
    @GetMapping("/{id}")
    @ApiOperation(value="获取岗位绑定角色详情",notes="")
    @ApiParam(name = "id",type = "Serializable",required = true)
    @PreAuthorize("hasAnyAuthority('SysStation:info','SysStation:SysStationRole:info') || hasRole('"+ BaseConstants.ADMINISTRATOR_ROLE_CODE +"') ")
    public BaseResult<SysStationRoleModel> info(@PathVariable("id") Serializable id, HttpServletRequest request, HttpServletResponse response){
        BaseResult<SysStationRoleModel> res = new BaseResult<>();
        res = super.info(id);
        return res;
    }

    /**
     * 修改岗位绑定角色
     * @param param
     * @param request
     * @param response
     * @return
     */
    @PutMapping
    @ApiOperation(value="修改岗位绑定角色",notes="")
    @PreAuthorize("hasAnyAuthority('SysStation:edit','SysStation:SysStationRole:edit') || hasRole('"+ BaseConstants.ADMINISTRATOR_ROLE_CODE +"') ")
    public BaseResult<SysStationRoleModel> edit(@RequestBody SysStationRoleModel param,HttpServletRequest request, HttpServletResponse response){
        BaseResult<SysStationRoleModel> res = new BaseResult<>();
        res =  super.edit(param);
        return res;
    }

    /**
     * 删除岗位绑定角色
     * @param ids
     * @param request
     * @param response
     * @return
     */
    @DeleteMapping
    @ApiOperation(value="删除岗位绑定角色",notes="注意参数是数字，就算单个，也要以数字的形式传递")
    @PreAuthorize("hasAnyAuthority('SysStation:del','SysStation:SysStationRole:del') || hasRole('"+ BaseConstants.ADMINISTRATOR_ROLE_CODE +"') ")
    public BaseResult<SysStationRoleModel> delete(@RequestBody String[] ids, HttpServletRequest request, HttpServletResponse response){
        BaseResult<SysStationRoleModel> res = new BaseResult<>();
        res = super.delete(ids);
        return res;
    }

}

